public class Demo11 {
    //在主线程中计算1+2+3+...+1000,在t线程中去打印结果
    private static long result=0;
    public static void main(String[] args) {
        Thread mainThread=Thread.currentThread();
        Thread t=new Thread(()->{
            try {
                mainThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(result);
        });
        t.start();
        for (int i = 1; i <=1000; i++) {
            result+=i;
        }
    }
}
